Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@babel/plugin-transform-block-scoped-functions
Advanced tools
Babel plugin to ensure function declarations at the block level are block scoped
The @babel/plugin-transform-block-scoped-functions npm package is designed to ensure that functions defined within blocks (such as if statements or for loops) are properly scoped to those blocks in environments that may not support this feature natively. This is particularly useful for ensuring compatibility with older browsers or JavaScript environments that do not fully implement ES6 scoping rules.
Function Scoping
This feature ensures that functions defined within a block are scoped to that block. This is important for compatibility with ES6, where functions are block-scoped, unlike in ES5 where they are function-scoped. The plugin transforms the code to work correctly in environments that do not support block scoping natively.
"use strict";\n\nif (true) {\n function foo() { return 1; }\n}\n\nfoo(); // Throws ReferenceError in ES6, transformed code works by scoping function within the block
Similar to @babel/plugin-transform-block-scoped-functions, this package transforms let and const declarations to be properly scoped to blocks, ensuring compatibility with older environments. While @babel/plugin-transform-block-scoped-functions focuses specifically on function declarations, @babel/plugin-transform-block-scoping handles all block-scoped declarations.
While not a direct equivalent, @babel/preset-env includes @babel/plugin-transform-block-scoped-functions as part of its comprehensive transformation of ES6+ code to be compatible with a target environment. It provides a broader range of transformations, including block-scoped functions, making it a more versatile choice for projects needing wide-ranging compatibility.
Babel plugin to ensure function declarations at the block level are block scoped
See our website @babel/plugin-transform-block-scoped-functions for more information.
Using npm:
npm install --save-dev @babel/plugin-transform-block-scoped-functions
or using yarn:
yarn add @babel/plugin-transform-block-scoped-functions --dev
v7.26.5 (2025-01-10)
babel-parser
import.defer()
form of import defer
(@babel-bot)babel-plugin-transform-block-scoped-functions
isInStrictMode
in Babel 7 (@liuxingbaoyu)babel-plugin-transform-typescript
babel-parser
@(a.b)()
(@liuxingbaoyu)babel-generator
, babel-parser
, babel-plugin-transform-flow-strip-types
, babel-types
babel-compat-data
, babel-preset-env
transform-typeof-symbol
compat data (@liuxingbaoyu)babel-generator
, babel-parser
, babel-types
babel-plugin-transform-nullish-coalescing-operator
FAQs
Babel plugin to ensure function declarations at the block level are block scoped
The npm package @babel/plugin-transform-block-scoped-functions receives a total of 15,095,913 weekly downloads. As such, @babel/plugin-transform-block-scoped-functions popularity was classified as popular.
We found that @babel/plugin-transform-block-scoped-functions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.